<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>PowerVR SDK</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<table width="100%">
  <tr>
    <td width="33%">
      <p align="left">&nbsp;<a href="http://www.imgtec.com"><img border="0" src="IMGLogo.jpg" width="200" height="30"></a></p>
    </td>
    <td width="33%">
      <p align="center"><font color="#808080" face="Arial" size="2">PowerVR Software Development Kit</a></font></p>
    </td>
    <td width="34%">
      <p align="right"><a href="http://www.powervr.com"><img border="0" src="PVRlogo.jpg" width="200" height="27"></a></p>
    </td>
  </tr>
</table>
<hr>
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>PVRTGlobal.h</h1><a href="PVRTGlobal_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/******************************************************************************</span>
00002 <span class="comment"></span>
00003 <span class="comment"> @File         PVRTGlobal.h</span>
00004 <span class="comment"></span>
00005 <span class="comment"> @Title        PVRTGlobal</span>
00006 <span class="comment"></span>
00007 <span class="comment"> @Version      </span>
00008 <span class="comment"></span>
00009 <span class="comment"> @Copyright    Copyright (C)  Imagination Technologies Limited.</span>
00010 <span class="comment"></span>
00011 <span class="comment"> @Platform     ANSI compatible</span>
00012 <span class="comment"></span>
00013 <span class="comment"> @Description  Global defines and typedefs for PVRTools</span>
00014 <span class="comment"></span>
00015 <span class="comment">******************************************************************************/</span>
00016 <span class="preprocessor">#ifndef _PVRTGLOBAL_H_</span>
00017 <span class="preprocessor"></span><span class="preprocessor">#define _PVRTGLOBAL_H_</span>
00018 <span class="preprocessor"></span>
00019 <span class="comment">/*!***************************************************************************</span>
00020 <span class="comment"> Macros</span>
00021 <span class="comment">*****************************************************************************/</span>
00022 <span class="preprocessor">#define PVRT_MIN(a,b)            (((a) &lt; (b)) ? (a) : (b))</span>
00023 <span class="preprocessor"></span><span class="preprocessor">#define PVRT_MAX(a,b)            (((a) &gt; (b)) ? (a) : (b))</span>
00024 <span class="preprocessor"></span><span class="preprocessor">#define PVRT_CLAMP(x, l, h)      (PVRT_MIN((h), PVRT_MAX((x), (l))))</span>
00025 <span class="preprocessor"></span>
<a name="l00026"></a><a class="code" href="PVRTGlobal_8h.html#a0">00026</a> <span class="comment">// avoid warning about unused parameter</span>
<a name="l00027"></a><a class="code" href="PVRTGlobal_8h.html#a1">00027</a> <span class="preprocessor">#define PVRT_UNREFERENCED_PARAMETER(x) ((void) x)</span>
<a name="l00028"></a><a class="code" href="PVRTGlobal_8h.html#a2">00028</a> <span class="preprocessor"></span>
00029 <span class="preprocessor">#if defined(_WIN32) &amp;&amp; !defined(UNDER_CE) &amp;&amp; !defined(__SYMBIAN32__) &amp;&amp; !defined(__BADA__) &amp;&amp; !defined(__QT__)  </span><span class="comment">/* Windows desktop */</span>
00030 <span class="preprocessor">    #define _CRTDBG_MAP_ALLOC</span>
<a name="l00031"></a><a class="code" href="PVRTGlobal_8h.html#a3">00031</a> <span class="preprocessor"></span><span class="preprocessor">    #include &lt;windows.h&gt;</span>
00032 <span class="preprocessor">    #include &lt;crtdbg.h&gt;</span>
00033 <span class="preprocessor">    #include &lt;tchar.h&gt;</span>
00034 <span class="preprocessor">#endif</span>
00035 <span class="preprocessor"></span>
00036 <span class="preprocessor">#if defined(UNDER_CE)</span>
00037 <span class="preprocessor"></span><span class="preprocessor">    #include &lt;windows.h&gt;</span>
00038 
00039 <span class="preprocessor">#ifndef _ASSERT</span>
00040 <span class="preprocessor"></span><span class="preprocessor">    #ifdef _DEBUG</span>
00041 <span class="preprocessor"></span><span class="preprocessor">        #define _ASSERT(X) { (X) ? 0 : DebugBreak(); }</span>
00042 <span class="preprocessor"></span><span class="preprocessor">    #else</span>
00043 <span class="preprocessor"></span><span class="preprocessor">        #define _ASSERT(X)</span>
00044 <span class="preprocessor"></span><span class="preprocessor">    #endif</span>
00045 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00046 <span class="preprocessor"></span>
00047 <span class="preprocessor">#ifndef _ASSERTE</span>
00048 <span class="preprocessor"></span><span class="preprocessor">    #ifdef _DEBUG</span>
00049 <span class="preprocessor"></span><span class="preprocessor">        #define _ASSERTE _ASSERT</span>
00050 <span class="preprocessor"></span><span class="preprocessor">    #else</span>
00051 <span class="preprocessor"></span><span class="preprocessor">        #define _ASSERTE(X)</span>
00052 <span class="preprocessor"></span><span class="preprocessor">    #endif</span>
00053 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00054 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT0(a,b)</span>
00055 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT1(a,b,c)</span>
00056 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT2(a,b,c,d)</span>
00057 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT3(a,b,c,d,e)</span>
00058 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT4(a,b,c,d,e,f)</span>
00059 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00060 <span class="preprocessor"></span>
00061 <span class="preprocessor">#if defined(_WIN32) &amp;&amp; !defined(__WINSCW__) &amp;&amp; !defined(__BADA__) &amp;&amp; !defined(__QT__)</span>
00062 <span class="preprocessor"></span>
00063 <span class="preprocessor">#else</span>
00064 <span class="preprocessor"></span><span class="preprocessor">#if defined(__linux__) || defined(__APPLE__)</span>
00065 <span class="preprocessor"></span><span class="preprocessor">    #define _ASSERT(a)((void)0)</span>
00066 <span class="preprocessor"></span><span class="preprocessor">    #define _ASSERTE(a)((void)0)</span>
00067 <span class="preprocessor"></span><span class="preprocessor">    #ifdef _DEBUG</span>
00068 <span class="preprocessor"></span><span class="preprocessor">        #ifndef _RPT0</span>
00069 <span class="preprocessor"></span><span class="preprocessor">        #define _RPT0(a,b) printf(b)</span>
00070 <span class="preprocessor"></span><span class="preprocessor">        #endif</span>
00071 <span class="preprocessor"></span><span class="preprocessor">        #ifndef _RPT1</span>
00072 <span class="preprocessor"></span><span class="preprocessor">        #define _RPT1(a,b,c) printf(b,c)</span>
00073 <span class="preprocessor"></span><span class="preprocessor">        #endif</span>
00074 <span class="preprocessor"></span><span class="preprocessor">    #else</span>
00075 <span class="preprocessor"></span><span class="preprocessor">        #ifndef _RPT0</span>
00076 <span class="preprocessor"></span><span class="preprocessor">        #define _RPT0(a,b)((void)0)</span>
00077 <span class="preprocessor"></span><span class="preprocessor">        #endif</span>
00078 <span class="preprocessor"></span><span class="preprocessor">        #ifndef _RPT1</span>
00079 <span class="preprocessor"></span><span class="preprocessor">        #define _RPT1(a,b,c)((void)0)</span>
00080 <span class="preprocessor"></span><span class="preprocessor">        #endif</span>
00081 <span class="preprocessor"></span><span class="preprocessor">    #endif</span>
00082 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT2(a,b,c,d)((void)0)</span>
00083 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT3(a,b,c,d,e)((void)0)</span>
00084 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT4(a,b,c,d,e,f)((void)0)</span>
00085 <span class="preprocessor"></span><span class="preprocessor">    #include &lt;stdlib.h&gt;</span>
00086 <span class="preprocessor">    #include &lt;string.h&gt;</span>
00087 <span class="preprocessor">    #define BYTE unsigned char</span>
00088 <span class="preprocessor"></span><span class="preprocessor">    #define WORD unsigned short</span>
00089 <span class="preprocessor"></span><span class="preprocessor">    #define DWORD unsigned long</span>
00090 <span class="preprocessor"></span>    <span class="keyword">typedef</span> <span class="keyword">struct </span>tagRGBQUAD {
00091     BYTE    rgbBlue;
00092     BYTE    rgbGreen;
00093     BYTE    rgbRed;
00094     BYTE    rgbReserved;
00095     } RGBQUAD;
00096 <span class="preprocessor">    #define BOOL int</span>
00097 <span class="preprocessor"></span><span class="preprocessor">    #define TRUE 1</span>
00098 <span class="preprocessor"></span><span class="preprocessor">    #define FALSE 0</span>
00099 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00100 <span class="preprocessor"></span><span class="preprocessor">    #define _CRT_WARN 0</span>
00101 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT0(a,b)</span>
00102 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT1(a,b,c)</span>
00103 <span class="preprocessor"></span><span class="preprocessor">    #define _RPT2(a,b,c,d)</span>
<a name="l00104"></a><a class="code" href="PVRTGlobal_8h.html#a4">00104</a> <span class="preprocessor"></span><span class="preprocessor">    #define _RPT3(a,b,c,d,e)</span>
<a name="l00105"></a><a class="code" href="PVRTGlobal_8h.html#a5">00105</a> <span class="preprocessor"></span><span class="preprocessor">    #define _RPT4(a,b,c,d,e,f)</span>
<a name="l00106"></a><a class="code" href="PVRTGlobal_8h.html#a6">00106</a> <span class="preprocessor"></span><span class="preprocessor">    #define _ASSERT(X)</span>
<a name="l00107"></a><a class="code" href="PVRTGlobal_8h.html#a7">00107</a> <span class="preprocessor"></span><span class="preprocessor">    #define _ASSERTE(X)</span>
<a name="l00108"></a><a class="code" href="PVRTGlobal_8h.html#a8">00108</a> <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00109"></a><a class="code" href="PVRTGlobal_8h.html#a9">00109</a> <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00110"></a><a class="code" href="PVRTGlobal_8h.html#a10">00110</a> <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00111"></a><a class="code" href="PVRTGlobal_8h.html#a11">00111</a> <span class="preprocessor"></span>
00112 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
00113 
00114 <span class="preprocessor">#define FREE(X)     { if(X) { free(X); (X) = 0; } }</span>
00115 <span class="preprocessor"></span>
00116 <span class="comment">// This macro is used to check at compile time that types are of a certain size</span>
00117 <span class="comment">// If the size does not equal the expected size, this typedefs an array of size 0</span>
<a name="l00118"></a><a class="code" href="PVRTGlobal_8h.html#a12">00118</a> <span class="comment">// which causes a compile error</span>
00119 <span class="preprocessor">#define PVRTSIZEASSERT(T, size) typedef int (sizeof_##T)[sizeof(T) == (size)]</span>
00120 <span class="preprocessor"></span>
00121 
00122 <span class="comment">/****************************************************************************</span>
<a name="l00123"></a><a class="code" href="PVRTGlobal_8h.html#a13">00123</a> <span class="comment">** Integer types</span>
00124 <span class="comment">****************************************************************************/</span>
00125 
00126 <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">char</span>        <a class="code" href="PVRTGlobal_8h.html#a14">PVRTint8</a>;
00127 <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">short</span>       <a class="code" href="PVRTGlobal_8h.html#a15">PVRTint16</a>;
00128 <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">int</span>         <a class="code" href="PVRTGlobal_8h.html#a16">PVRTint32</a>;
00129 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>      <a class="code" href="PVRTGlobal_8h.html#a17">PVRTuint8</a>;
<a name="l00130"></a><a class="code" href="PVRTGlobal_8h.html#a14">00130</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>     <a class="code" href="PVRTGlobal_8h.html#a18">PVRTuint16</a>;
<a name="l00131"></a><a class="code" href="PVRTGlobal_8h.html#a15">00131</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>       <a class="code" href="PVRTGlobal_8h.html#a19">PVRTuint32</a>;
<a name="l00132"></a><a class="code" href="PVRTGlobal_8h.html#a16">00132</a> 
<a name="l00133"></a><a class="code" href="PVRTGlobal_8h.html#a17">00133</a> <span class="preprocessor">#if !defined(__BADA__) &amp;&amp; (defined(__int64) || defined(_WIN32))</span>
<a name="l00134"></a><a class="code" href="PVRTGlobal_8h.html#a18">00134</a> <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">signed</span> __int64     <a class="code" href="PVRTGlobal_8h.html#a20">PVRTint64</a>;
<a name="l00135"></a><a class="code" href="PVRTGlobal_8h.html#a19">00135</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> __int64   <a class="code" href="PVRTGlobal_8h.html#a21">PVRTuint64</a>;
00136 <span class="preprocessor">#elif defined(TInt64)</span>
00137 <span class="preprocessor"></span><span class="keyword">typedef</span> TInt64             <a class="code" href="PVRTGlobal_8h.html#a20">PVRTint64</a>;
00138 <span class="keyword">typedef</span> TUInt64            <a class="code" href="PVRTGlobal_8h.html#a21">PVRTuint64</a>;
00139 <span class="preprocessor">#else</span>
00140 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span>   <a class="code" href="PVRTGlobal_8h.html#a20">PVRTint64</a>;
00141 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> <a class="code" href="PVRTGlobal_8h.html#a21">PVRTuint64</a>;
00142 <span class="preprocessor">#endif</span>
00143 <span class="preprocessor"></span>
<a name="l00144"></a><a class="code" href="PVRTGlobal_8h.html#a20">00144</a> <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTint8,   1);
<a name="l00145"></a><a class="code" href="PVRTGlobal_8h.html#a21">00145</a> <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTuint8,  1);
00146 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTint16,  2);
00147 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTuint16, 2);
00148 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTint32,  4);
00149 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTuint32, 4);
00150 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTint64,  8);
00151 <a class="code" href="PVRTGlobal_8h.html#a13">PVRTSIZEASSERT</a>(PVRTuint64, 8);
00152 
00153 <span class="comment">/****************************************************************************</span>
00154 <span class="comment">** swap template function</span>
00155 <span class="comment">****************************************************************************/</span>
00156 <span class="comment">/*!***************************************************************************</span>
00157 <span class="comment"> @Function      PVRTswap</span>
00158 <span class="comment"> @Input         a Type a</span>
00159 <span class="comment"> @Input         b Type b</span>
00160 <span class="comment"> @Description   A swap template function that swaps a and b</span>
00161 <span class="comment">*****************************************************************************/</span>
00162 
00163 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
00164 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="PVRTGlobal_8h.html#a30">PVRTswap</a>(T&amp; a, T&amp; b)
00165 {
00166     T temp = a;
00167     a = b;
00168     b = temp;
<a name="l00169"></a><a class="code" href="PVRTGlobal_8h.html#a30">00169</a> }
00170 
00171 <span class="preprocessor">#ifdef _UITRON_</span>
00172 <span class="preprocessor"></span><span class="keyword">template</span> <span class="keywordtype">void</span> PVRTswap&lt;unsigned char&gt;(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>&amp; a, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>&amp; b);
00173 <span class="preprocessor">#endif</span>
00174 <span class="preprocessor"></span>
00175 <span class="comment">/*!***************************************************************************</span>
00176 <span class="comment"> @Function      PVRTByteSwap</span>
00177 <span class="comment"> @Input         pBytes A number</span>
00178 <span class="comment"> @Input         i32ByteNo Number of bytes in pBytes</span>
00179 <span class="comment"> @Description   Swaps the endianness of pBytes in place</span>
00180 <span class="comment">*****************************************************************************/</span>
00181 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="PVRTGlobal_8h.html#a31">PVRTByteSwap</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pBytes, <span class="keywordtype">int</span> i32ByteNo)
00182 {
00183     <span class="keywordtype">int</span> i = 0, j = i32ByteNo - 1;
00184 
00185     <span class="keywordflow">while</span>(i &lt; j)
00186         PVRTswap&lt;unsigned char&gt;(pBytes[i++], pBytes[j--]);
<a name="l00187"></a><a class="code" href="PVRTGlobal_8h.html#a31">00187</a> }
00188 
00189 <span class="comment">/*!***************************************************************************</span>
00190 <span class="comment"> @Function      PVRTByteSwap32</span>
00191 <span class="comment"> @Input         ui32Long A number</span>
00192 <span class="comment"> @Returns       ui32Long with its endianness changed</span>
00193 <span class="comment"> @Description   Converts the endianness of an unsigned long</span>
00194 <span class="comment">*****************************************************************************/</span>
00195 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="PVRTGlobal_8h.html#a32">PVRTByteSwap32</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> ui32Long)
00196 {
00197     <span class="keywordflow">return</span> ((ui32Long&amp;0x000000FF)&lt;&lt;24) + ((ui32Long&amp;0x0000FF00)&lt;&lt;8) + ((ui32Long&amp;0x00FF0000)&gt;&gt;8) + ((ui32Long&amp;0xFF000000) &gt;&gt; 24);
00198 }
00199 
00200 <span class="comment">/*!***************************************************************************</span>
00201 <span class="comment"> @Function      PVRTByteSwap16</span>
<a name="l00202"></a><a class="code" href="PVRTGlobal_8h.html#a32">00202</a> <span class="comment"> @Input         ui16Short A number</span>
00203 <span class="comment"> @Returns       ui16Short with its endianness changed</span>
00204 <span class="comment"> @Description   Converts the endianness of a unsigned short</span>
00205 <span class="comment">*****************************************************************************/</span>
00206 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="PVRTGlobal_8h.html#a33">PVRTByteSwap16</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> ui16Short)
00207 {
00208     <span class="keywordflow">return</span> (ui16Short&gt;&gt;8) | (ui16Short&lt;&lt;8);
00209 }
00210 
00211 <span class="comment">/*!***************************************************************************</span>
00212 <span class="comment"> @Function      PVRTIsLittleEndian</span>
00213 <span class="comment"> @Returns       True if the platform the code is ran on is little endian</span>
<a name="l00214"></a><a class="code" href="PVRTGlobal_8h.html#a33">00214</a> <span class="comment"> @Description   Returns true if the platform the code is ran on is little endian</span>
00215 <span class="comment">*****************************************************************************/</span>
00216 <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="PVRTGlobal_8h.html#a34">PVRTIsLittleEndian</a>()
00217 {
00218     <span class="keyword">static</span> <span class="keywordtype">bool</span> bLittleEndian;
00219     <span class="keyword">static</span> <span class="keywordtype">bool</span> bIsInit = <span class="keyword">false</span>;
00220 
00221     <span class="keywordflow">if</span>(!bIsInit)
00222     {
00223         <span class="keywordtype">short</span> <span class="keywordtype">int</span> word = 0x0001;
00224         <span class="keywordtype">char</span> *byte = (<span class="keywordtype">char</span>*) &amp;word;
<a name="l00225"></a><a class="code" href="PVRTGlobal_8h.html#a34">00225</a>         bLittleEndian = byte[0] ? <span class="keyword">true</span> : <span class="keyword">false</span>;
00226         bIsInit = <span class="keyword">true</span>;
00227     }
00228 
00229     <span class="keywordflow">return</span> bLittleEndian;
00230 }
00231 
00232 <span class="preprocessor">#endif // _PVRTGLOBAL_H_</span>
00233 <span class="preprocessor"></span>
00234 <span class="comment">/*****************************************************************************</span>
00235 <span class="comment"> End of file (Tools.h)</span>
00236 <span class="comment">*****************************************************************************/</span>
00237 
</pre></div><br>
<br>
<P align=left><FONT size=2><STRONG><A 
   href="http://www.imgtec.com/powervr/insider/legal/index.asp">Copyright</A> � 
   1999-2008, Imagination Technologies Ltd.</STRONG></FONT></P>
<hr>
<address style="align: left;"><small><FONT color=f0f>
Generated by <a href="http://www.doxygen.org/index.html">DOXYGEN</a> 1.3.6</small></address>
</body>
</html>
